using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Model;

namespace FirebirdTool
{
    public partial class FrmData : DevExpress.XtraEditors.XtraForm
    {
        LoaiTrangPhucBOCollection loaiTrangPhucBOCollection = null;

        public FrmData()
        {
            InitializeComponent();

            Session.DB = @"E:\DHT\RMS\ac\db\ACDB.FDB";

            btnRefresh_Click(null, null);

            this.btnSave.Click += new EventHandler(btnSave_Click);
            this.btnDelete.Click += new EventHandler(btnDelete_Click);
            this.btnRefresh.Click += new EventHandler(btnRefresh_Click);
        }

        void btnRefresh_Click(object sender, EventArgs e)
        {
            this.repositoryItemLookUpEdit1.DataSource = LoaiTrangPhucBOList.GetLoaiTrangPhucBOList(true);
            this.repositoryItemLookUpEdit1.ValueMember = "Key";
            this.repositoryItemLookUpEdit1.DisplayMember = "Value";

            LoaiTrangPhucBOCollection loaiTrangPhucBOCollection = LoaiTrangPhucBOCollection.GetLoaiTrangPhucBOCollection(null, true);
            this.bindingSource1.DataSource = loaiTrangPhucBOCollection;
        }

        void btnDelete_Click(object sender, EventArgs e)
        {
            int? LoaiTrangPhucID = StaticUtil.GetRealInt(this.gridView1.GetFocusedRowCellValue("LoaiTrangPhucID"));
            if (LoaiTrangPhucID != null)
            {
                LoaiTrangPhucBO.DeleteLoaiTrangPhucBO(LoaiTrangPhucID.Value);

                try
                {
                    this.gridView1.DeleteSelectedRows();
                }
                catch { }
            }
        }

        void btnSave_Click(object sender, EventArgs e)
        {
            this.bindingSource1.EndEdit();
            this.loaiTrangPhucBOCollection = (LoaiTrangPhucBOCollection)this.bindingSource1.DataSource;
            this.loaiTrangPhucBOCollection = this.loaiTrangPhucBOCollection.Save();
            this.bindingSource1.DataSource = this.loaiTrangPhucBOCollection.Clone();
        }
    }
}